package stickyhand.ui;

import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.table.AbstractTableModel;

import stickyhand.NZB;
import stickyhand.NZBFile;
import stickyhand.NZBGroup;

public class SHGetInfoTableModel extends AbstractTableModel {
	private final String[] colNames = {"name", "date", "size", 
			"segments", "poster", "groups"};
	private NZB nzb_info;
	
	public SHGetInfoTableModel(NZB nzb_info) {
		super();
		this.nzb_info = nzb_info;
	}

	public int getColumnCount() {
		return colNames.length;
	}

	public String getColumnName(int col) {
		return colNames[col].toString();
	}
	
	public int getRowCount() {
		return nzb_info.getNumFiles();
	}

	public Object getValueAt(int row, int col) {
		LinkedList<NZBFile> files = nzb_info.getFileList();
		NZBFile file = files.get(row);
		
		switch (col) {
		case 0:
			return file.getName();
		case 1:
			return file.getDate();
		case 2:
			return SHJList.formatBytes(file.getBytes());
		case 3:
			return file.getNumSegments();
		case 4:
			return file.getPoster();
		case 5:
			LinkedList<NZBGroup> groups = file.getGroupList();
			StringBuilder allGroups = new StringBuilder();
			
			Iterator grpItr = groups.iterator();
			while (grpItr.hasNext()) {
				NZBGroup group = (NZBGroup)grpItr.next();
				allGroups.append(group.getName() + " ");
			}
			return allGroups.toString();
		}
		
		return null;
	}

}
